package com.hnust.root.dao.entity.domain;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
import com.hnust.root.common.base.status.UserStatus;
import lombok.Data;

import java.io.Serializable;
import java.time.LocalDateTime;

/**
 * 后台管理用户表
 */
@Data
@TableName("sys_user")
public class Manager implements Serializable  {

    private static final long serialVersionUID = 1L;
    @TableId
    private Integer id;
    /**
     * 账号
     */
    @TableField("username")
    private String username;
    /**
     * 名字
     */
    @TableField("name")
    private String name;
    /**
     * 密码
     */
    @TableField("password")
    private String password;
    /**
     * md5密码盐
     */
    @TableField("salt")
    private String salt;
    /**
     * 联系电话
     */
    @TableField("phone")
    private String phone;
    /**
     * 备注
     */
    @TableField("tips")
    private String tips;
    /**
     * 状态 1:正常 2:禁用
     */
    @TableField("status")
    private Integer state;
    /**
     * 创建时间
     */
    @TableField("create_time")
    @JsonDeserialize(using = LocalDateTimeDeserializer.class)
    @JsonSerialize(using = LocalDateTimeSerializer.class)
    private LocalDateTime createTime;
    /**
     * 更新时间
     */
    @TableField("update_time")
    @JsonDeserialize(using = LocalDateTimeDeserializer.class)
    @JsonSerialize(using = LocalDateTimeSerializer.class)
    private LocalDateTime updateTime;

    /**
     * 返回用户是否可用
     * @return
     */
    public boolean userIsValid() {
        return this.state == UserStatus.NOMAL.getCode();
    }


    protected Serializable pkVal() {
        return this.id;
    }

}
